using System;
using System.Reflection;
using System.Text;

public static class HttpRequestForm
{
    public static string GetString(object o)
    {
        if (o == null)
        {
            return "";
        }

        Type type = o.GetType();
        FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
        if (fields.Length == 0)
        {
            return "";
        }
        
        //key1=value1&key2=value2
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0, count = fields.Length; i < count; ++i)
        {
            if (i != 0)
            {
                stringBuilder.Append('&');
            }
            
            stringBuilder.Append(fields[i].Name);
            stringBuilder.Append('=');
            stringBuilder.Append(fields[i].GetValue(o));
        }

        return stringBuilder.ToString();
    } 
}